﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using System.Drawing;
using docTissV2.Classes;

namespace docTissV2
{
    public partial class rbbDocTiss
    {
        private void rbbDocTiss_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void tbtnGerenciarGuias_Click(object sender, RibbonControlEventArgs e)
        {
            if (tbtnGerenciarGuias.Checked)
            {
                Globals.ThisAddIn.GerenciaGuiaCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_GerenciaGuia(), "Gerenciador de Guias");
                Globals.ThisAddIn.GerenciaGuiaCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
                Globals.ThisAddIn.GerenciaGuiaCTP.Width = 315;
                Globals.ThisAddIn.GerenciaGuiaCTP.Visible = true;

                Globals.ThisAddIn.GerenciaGuiaCTP.VisibleChanged += new EventHandler(GerenciaGuiaCTP_VisibleChanged);
            }
            else
                Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.GerenciaGuiaCTP);
        }

        private void GerenciaGuiaCTP_VisibleChanged(object sender, EventArgs e)
        {
            tbtnGerenciarGuias.Checked = Globals.ThisAddIn.GerenciaGuiaCTP.Visible;
        }

        private void tbtnModuloConfiguracao_Click(object sender, RibbonControlEventArgs e)
        {
            if (tbtnModuloConfiguracao.Checked)
            {
                Globals.ThisAddIn.ModuloConfiguracaoCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_ModuloConfiguracao(), "Módulo de configurações");
               // Globals.ThisAddIn.ModuloConfiguracaoCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Prestador(), "Prestador");
               // Globals.ThisAddIn.ModuloConfiguracaoCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Operadora(), "Operadora");
               // Globals.ThisAddIn.ModuloConfiguracaoCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Configuracoes(), "Configurações");
                Globals.ThisAddIn.ModuloConfiguracaoCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
                Globals.ThisAddIn.ModuloConfiguracaoCTP.Width = 610;  // 550
                Globals.ThisAddIn.ModuloConfiguracaoCTP.Height = 530;  // 460
                Globals.ThisAddIn.ModuloConfiguracaoCTP.Visible = true;

                Globals.ThisAddIn.ModuloConfiguracaoCTP.VisibleChanged += new EventHandler(ModuloConfiguracaoCTP_VisibleChanged);
            }
            else
                Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.ModuloConfiguracaoCTP);
        }

        private void ModuloConfiguracaoCTP_VisibleChanged(object sender, EventArgs e)
        {
            tbtnModuloConfiguracao.Checked = Globals.ThisAddIn.ModuloConfiguracaoCTP.Visible;
        }

        private void tbtnLogin_Click(object sender, RibbonControlEventArgs e)
        {
            bool loggedIn = true;
            if (!tbtnLogin.Checked)
            {
                Globals.Ribbons.rbbDocTiss.tbtnGerenciarGuias.Enabled = false;
                Globals.Ribbons.rbbDocTiss.tbtnGerenciarGuias.Checked = false;

                AddinUtils.UsuarioID = -1;
                AddinUtils.CPF_CNPJ = string.Empty;
                AddinUtils.PrestadorNome = string.Empty;
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Image = new Bitmap(docTissV2.Properties.Resources.login32);
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Label = "Login";

                loggedIn = false;

                Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.LoginCTP);
                Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.GerenciaGuiaCTP);
            }

            if (loggedIn)
            {
                Globals.ThisAddIn.LoginCTP = Globals.ThisAddIn.CustomTaskPanes.Add(new uc_Login(), "Login");
                Globals.ThisAddIn.LoginCTP.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
                Globals.ThisAddIn.LoginCTP.Width = 125;
                Globals.ThisAddIn.LoginCTP.Height = 155;
                Globals.ThisAddIn.LoginCTP.Visible = true;
                Globals.ThisAddIn.LoginCTP.Control.Focus();

                Globals.ThisAddIn.LoginCTP.VisibleChanged += new EventHandler(LoginCTP_VisibleChanged);

                Globals.Ribbons.rbbDocTiss.tbtnLogin.Image = new Bitmap(docTissV2.Properties.Resources.logoff32);
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Label = "Logoff";
            }

            tbtnLogin.Checked = loggedIn;
        }

        private void LoginCTP_VisibleChanged(object sender, EventArgs e)
        {
            tbtnLogin.Checked = Globals.ThisAddIn.LoginCTP.Visible;
            if (tbtnLogin.Checked)
            {
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Image = new Bitmap(docTissV2.Properties.Resources.logoff32);
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Label = "Logoff";
            }
            else
            {
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Image = new Bitmap(docTissV2.Properties.Resources.login32);
                Globals.Ribbons.rbbDocTiss.tbtnLogin.Label = "Login";
            }
        }
    }
}
